import subprocess


def do_name_server_lookup():
    """
    域名查询
    """

    print('$ nslookup')
    """
    相当于在终端执行：
        nslookup www.python.org
    """
    p = subprocess.Popen(['nslookup'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    output, err = p.communicate(b'www.python.org')
    print(output.decode('utf-8'))
    print('Exit code:', p.returncode)


if __name__ == "__main__":
    do_name_server_lookup()
